//
//  ResidenceLoginView.m
//  Base_App
//
//  Created by Yutian Duan on 2019/6/10.
//  Copyright © 2019年 Wanwin. All rights reserved.
//

#import "ResidenceLoginView.h"
#import "LineProgressView.h"
#import "ResidenceIntegralListView.h"

@interface ResidenceLoginView ()

@property (nonatomic, strong) UIImageView *bgImageView;
///! title
@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) UIView *loginView;
///! 会员
@property (nonatomic, strong) UILabel *menberName;
@property (nonatomic, strong) UILabel *userName;
@property (nonatomic, strong) UILabel *vipCount;

///! 积分
@property (nonatomic, strong) UILabel *countLabel;

@property (nonatomic, strong) LineProgressView *progressView;
@property (nonatomic, strong) UILabel *progressLabel;

///! 积分记录
@property (nonatomic, strong) ResidenceIntegralListView *listView;
///! 账户资料
@property (nonatomic, strong) UIView *accountView;

@end

@implementation ResidenceLoginView

///!
- (UIView *)loginView {
  if (!_loginView) {
    _loginView = [[UIView alloc] initWithFrame:CGRectMake(0, _titleLabel.yt_bottom, ScreenWidth, _bgImageView.yt_height - _titleLabel.yt_bottom)];
    [_bgImageView addSubview:_loginView];
    
    //!  高级会员
    _menberName = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, _loginView.yt_width, 20)];
    _menberName.textColor = DEF_GRAY;
    _menberName.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
    _menberName.textAlignment = NSTextAlignmentCenter;
    [_loginView addSubview:_menberName];
    
    /// 会员名字
    _userName = [[UILabel alloc] initWithFrame:CGRectMake(0, _menberName.yt_bottom + 5, _menberName.yt_width, 20)];
    _userName.textColor = [UIColor whiteColor];
    _userName.font = [UIFont fontWithName:@"Helvetica-Bold" size:17.0f];
    _userName.textAlignment = NSTextAlignmentCenter;
    [_loginView addSubview:_userName];
    
    ///! 会员等级
    UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, _userName.yt_bottom + 5, 142, 20)];
    imageView.image = [UIImage imageNamed:@"Residence_vip_golden"];
    imageView.yt_centerX = _loginView.yt_width/2;
    [_loginView addSubview:imageView];
    
    _vipCount = [[UILabel alloc] initWithFrame:CGRectMake(0, imageView.yt_top, _userName.yt_width, imageView.yt_height)];
    _vipCount.textColor = DEF_BLACK;
    _vipCount.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
    _vipCount.textAlignment = NSTextAlignmentCenter;
    [_loginView addSubview:_vipCount];
    
    
  }
  
  return _loginView;
}

- (ResidenceIntegralListView *)listView {
  if (!_listView) {
    CGFloat rowH = 30;
    _listView = [[ResidenceIntegralListView alloc] initWithFrame:CGRectMake(30, _progressLabel.yt_bottom + 20, self.yt_width - 60, 44 + rowH * 3)];
    _listView.rowHeight = rowH;
    [_listView setup];
    [self addSubview:_listView];
  }
  return _listView;
}

- (UIView *)accountView {
  if (!_accountView) {
    _accountView = [[UIView alloc] initWithFrame:CGRectMake(self.listView.yt_left, self.listView.yt_bottom + 10, self.listView.yt_width, 44)];
    _accountView.layer.masksToBounds = YES;
    _accountView.layer.cornerRadius = 8;
    _accountView.layer.borderWidth = 0.5;
    [self addSubview:_accountView];
    
    
    ///!
    UIImageView *listImageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 12, 20, 20)];
    listImageView.image = [UIImage imageNamed:@"Residence_UserAccount"];
    [_accountView addSubview:listImageView];
    
    UILabel *countTitle = [[UILabel alloc] initWithFrame:CGRectMake(listImageView.yt_right + 2, 0, 120, _accountView.yt_height)];
    countTitle.textAlignment = NSTextAlignmentLeft;
    countTitle.textColor = DEF_BLACK;
    countTitle.font = [UIFont fontWithName:@"Helvetica-Bold" size:16.0f];
    countTitle.text = YTLocalizedString(@"账户资料");
    [_accountView addSubview:countTitle];
    
    UIImageView *arrowImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 15, 20, 20)];
    arrowImageView.yt_centerY = _accountView.yt_height/2;
    arrowImageView.yt_right = self.yt_width - listImageView.yt_left;
    [_accountView addSubview:arrowImageView];
    
  }
  return _accountView;
}

- (instancetype)initWithFrame:(CGRect)frame {
  self = [super initWithFrame:frame];
  if (self) {
    self.backgroundColor = [UIColor whiteColor];
    [self createViews];
  }
  return self;
}

- (void)createViews {
  
  
  //!
  _bgImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.yt_width, self.yt_width * ITEMPRO)];
  _bgImageView.clipsToBounds = YES;
  _bgImageView.contentMode = UIViewContentModeScaleAspectFill;
  _bgImageView.image = [UIImage imageNamed:@"Residence_Logined"];
  [self addSubview:_bgImageView];
  
  
  //！
  _titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(20, 20, 120, 40)];
  _titleLabel.text = YTLocalizedString(@"账户");
  _titleLabel.textColor = [UIColor whiteColor];
  _titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:20.0f];
  [_bgImageView addSubview:_titleLabel];
  _titleLabel.yt_bottom = _bgImageView.yt_height/2;
  
  self.loginView.hidden = NO;
  

  
  ///! 积分
  _countLabel = [[UILabel alloc] initWithFrame:CGRectMake(25, _bgImageView.yt_bottom + 20, self.yt_width - 50, 25)];
  _countLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15.0f];
  _countLabel.textAlignment = NSTextAlignmentLeft;
  _countLabel.textColor = DEF_GRAY;
  [self addSubview:_countLabel];
  
  ///!
  UILabel *noteLabel = [[UILabel alloc] initWithFrame:CGRectMake(_countLabel.yt_left, _countLabel.yt_bottom, _countLabel.yt_width, 13)];
  noteLabel.textColor = DEF_BLACK;
  noteLabel.textAlignment = NSTextAlignmentLeft;
  noteLabel.text = YTLocalizedString(@"累积达指定积分可升级会员等级(兑换后不扣减)");
  noteLabel.font = [UIFont systemFontOfSize:11];
  [self addSubview:noteLabel];
  
  _progressView = [[LineProgressView alloc] initWithFrame:CGRectMake(noteLabel.yt_left, noteLabel.yt_bottom + 5, self.yt_width - noteLabel.yt_left - 80 - 100, 5)];
  [self addSubview:_progressView];
  
  _progressLabel = [[UILabel alloc] initWithFrame:CGRectMake(_progressView.yt_right + 3, 0, 50, 20)];
  _progressLabel.textColor = DEF_RED;
  _progressLabel.font = [UIFont systemFontOfSize:13];
  _progressLabel.textAlignment = NSTextAlignmentLeft;
  [self addSubview:_progressLabel];
  _progressLabel.yt_centerY = _progressView.yt_centerY;

  ///! 查看特权
  _lookRightButton = [[UIButton alloc] initWithFrame:CGRectMake(_progressLabel.yt_right + 10, _progressLabel.yt_top, 50, 20)];
  _lookRightButton.titleLabel.font = [UIFont systemFontOfSize:11];
  [_lookRightButton setTitleColor:DEF_RED forState:UIControlStateNormal];
  [self addSubview:_lookRightButton];

  NSDictionary *styleDic = @{
                             NSUnderlineStyleAttributeName:@(NSUnderlineStyleSingle),
                             NSForegroundColorAttributeName:DEF_RED
                             };
  
  NSMutableAttributedString *attribtStr = [[NSMutableAttributedString alloc] initWithString:YTLocalizedString(@"查看特权") attributes:styleDic];
  [_lookRightButton setAttributedTitle:attribtStr forState:UIControlStateNormal];
  
  //TODO:
  self.listView.hidden = NO;
  self.accountView.hidden = NO;
  
  self.yt_height = self.accountView.yt_bottom + 20;

  
}

- (void)setupData {
  
  _menberName.text = @"高级会员";
  _userName.text = @"HANBERG CHAN";
  _vipCount.text = @"VIP !(*@!))!";
  

  
  _countLabel.text = [NSString stringWithFormat:@"%@：%@",YTLocalizedString(@"积分结余"),@"300,250Pt."];
  
  
  _progressView.progress = 112/150.0;
  _progressLabel.text = @"112/150";

  
  
  
  
}


@end
